package com.huike.framework.interceptor;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.huike.common.core.domain.model.LoginUser;
import com.huike.common.utils.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;
@Component
public class MyMetaObjectHandler  implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
       this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
       //自动填充创建人
        this.strictInsertFill(metaObject, "createBy", String.class, SecurityUtils.getUsername());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
        this.setFieldValByName("updateBy",SecurityUtils.getUsername() , metaObject);

    }
//    public String getLoginUser() {
//        LoginUser loginUser = SecurityUtils.getLoginUser();
//
//        if (loginUser != null) {
//            return loginUser.getUser().getUserName();
//        }
//        return "1";
//    }
}
